
import { param2Obj } from './utils'

const tokens = {
    a: {
        token: 'studenttoken'
    },
    b: {
        token: 'teacher-token'
    },
    c:{
        token:'supermanager-token'
    }
}

// const usercheck = {
//     username: 'c',
//     password: '123456',
//     role: 'supermanager'
// }

const users = {
    'studenttoken': {
        roles: [''],
        avatar: 'xxx',
        username: 'student',
        menuList: [
            'homepage',
            'first',
            'homework',
            'homeworklist',
            'systemmanager',
            'menu',
            'author'   
            ]
    },
    'teacher-token':{
        username: 'teacher',
        menuList:[
            'homepage',
            'first',
        ]
    },
    'supermanager-token':{
        username:'sm01',
        menuList:[
            'first',
            'homepage',
            'systemmanager',
            'menubar',
            'author',
        ]
    }
    
}

export default {
    login: res => {
        const { username } = JSON.parse(res.body)
        const token = tokens[username]
        if (token) {
            return {
                error: 0,
                message: 'successful',
                data: {
                    token
                }
            }
        }
        return {
            error: 60204,
            message: 'Account and password are incorrect.'
        }
    },
    getInfo: res => {
        const { token } = param2Obj(res.url)
        const info = users['studenttoken']
        if (info) {
            return {
                error: 0,
                data: info
            }
        }
        return {
            error: 50008,
            message: 'Login failed, unable to get user details.'
        }
    },
    logout: () => {
        return {
            error: 0,
            data: 'successful'
        }
    }

}